package com.eric.domain.po;
import com.eric.components.MyInsertListener;
import com.mybatisflex.annotation.*;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
@Table(value = "tb_account" ,onInsert = MyInsertListener.class)
public class Account implements Serializable {
    @Id(keyType = KeyType.Auto)
    private Long id;
    private String userName;
    private Integer age;
    private Integer version;
    @Column(isLogicDelete = true,onInsertValue = "0")
    private Integer isDeleted;

    @Column(value = "create_time", onInsertValue = "now()")
//    这里通过@Table注解中的onInsert来自动插入当前时间
    private Date createTime;

    @Column(value = "update_time",onInsertValue = "now()", onUpdateValue = "now()")
    private Date updateTime;

  /*一对一，  记住，括号中的"id"指的是Account实体类中，Integer id 中的id,
     "accountId"指的是 Integer accountId中的accountId
      selfField指的是本实体类中的属性，targetField指关联实体类中关联的属性
      */
    @RelationOneToOne(selfField = "id",targetField = "accountId")
    private IDCard idCard;

//  一对多，id自己实体类的字段id,targetField指向的是多的实体类对象的accountId属性
    @RelationOneToMany(selfField ="id",targetField = "accountId")
    private List<Book> bookList;

//    一对多，但是不用List，而是用Map
    @RelationOneToMany(selfField = "id",targetField = "accountId",mapKeyField = "id")
    private Map<Long,Book> bookMap;

//    Account和Role的关系是多对多关系
    @RelationManyToMany(

            joinTable = "tb_role_mapping",//中间表
//            selfField指的是Account实体类的属性值id，joinSelfColumn的"account_id"指的是中间表中的account_id字段
            selfField = "id",joinSelfColumn = "account_id",
//            targetField指的是Role实体类的属性值id，joinTargetColumn指的是中间表中的role_id字段
            targetField = "id",joinTargetColumn = "role_id"
    )
    private List<Role> roles;


}